package com.noob.assessment.web.interceptor;

/**
 * 用户上下文
 */
public class UserContext {

    private static final ThreadLocal<String> CONTEXT = new ThreadLocal<>();

    /**
     * 将生成的用户id添加到thread loca中存储
     *
     * @param userId
     */
    public static void addUserContext(String userId) {
        CONTEXT.remove();
        CONTEXT.set(userId);
    }

    /**
     * 获取用户id
     * @return
     */
    public static String getUserId() {
        return CONTEXT.get();
    }

}
